<template>
  <div>
    <div class="header">
      <img src="/imgs/login-logo.png" alt />
    </div>
    <div class="content">
      <img src="/imgs/login-bg.jpg" />
      <div class="loginBox">
        <div class="login">账号登录</div>
        <div class="s"></div>
        <div class="codeLogin">扫码登录</div>
        <div class="logins">
          <input type="text" placeholder="邮箱/手机号码/小米ID" v-model="username" />
          <input type="password" placeholder="密码" v-model="password" />
          <input type="button" value="登录" @click="userLogin" />
        </div>
        <div class="register">
          <span @click="register">手机短信登录/注册</span>
          <span>立即注册</span>
          <span>忘记密码？</span>
        </div>
      </div>
    </div>
    <div class="footer">
      <p>
        <span>简体</span>
        <span>|</span>
        <span>繁体</span>
        <span>|</span>
        <span>English</span>
        <span>|</span>
        <span>常见问题</span>
        <span>|</span>
        <span>隐私政策</span>
      </p>
      <p>
        <span>小米公司版权所有-京ICP备10046444-</span>
        <span>京公网安备11010802020134号-京ICP证110507号</span>
      </p>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import VueCookies from "vue-cookies";
import { mapMutations } from "vuex";
export default {
  name: "login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    ...mapMutations(["getUserName"]),
    register() {
      axios
        .post("/user/register", {
          username: "lin_xi",
          password: "123456789",
          email: "648771303@qq.com",
        })
        .then((res) => {
          window.console.log(res);
        })
        .catch((err) => window.console.log(err));
    },
    userLogin() {
      const userobj = {
        username: this.username,
        password: this.password,
      };
      axios
        .post("/user/login", userobj)
        .then((res) => {
          VueCookies.set("userId", res.id);
          this.getUserName(res.username);
          if (res) this.$router.push("/");
        })
        .catch((err) => window.console.log(err));
    },
  },
};
</script>


<style lang="scss" scoped>
@import "../assets/scss/config.scss";
@import "../assets/scss/reset.scss";
.header {
  height: 112px;
  background: rgba(255, 255, 255, 1);
  img {
    margin: 0 20%;
  }
}

.content {
  position: relative;
  img {
    width: 100%;
  }
  .loginBox {
    width: 21%;
    height: 89%;
    background: rgba(255, 255, 255, 1);
    position: absolute;
    left: 59%;
    top: 6%;
    .login {
      font-size: 4.5%;
      color: #f60;
      top: 8%;
      left: 18%;
      position: absolute;
      cursor: pointer;
    }
    .s {
      width: 0.5%;
      height: 5%;
      background-color: $colorF;
      top: 8%;
      left: 50%;
      position: absolute;
    }
    .codeLogin {
      color: #656565;
      top: 8%;
      left: 59%;
      position: absolute;
      cursor: pointer;
    }
    .logins {
      input {
        width: 85%;
        height: 15%;
        border: solid 1px $colorE;
      }
      :nth-child(1) {
        top: 22%;
        left: 7.5%;
        position: absolute;
        text-indent: 3%;
      }
      :nth-child(2) {
        top: 40%;
        left: 7.5%;
        position: absolute;
        text-indent: 3%;
      }
      :nth-child(3) {
        top: 60%;
        left: 8%;
        position: absolute;
        text-indent: 3%;
        border: none;
        background-color: $colorA;
        color: #fff;
        cursor: pointer;
      }
    }
    .register {
      width: 100%;
      top: 78%;
      left: 7.5%;
      position: absolute;
      span {
        cursor: pointer;
      }
      span:nth-child(1) {
        color: $colorA;
        margin-right: 10%;
      }
      span:nth-child(2) {
        margin-right: 3%;
        color: $colorD;
      }
      span:nth-child(3) {
        color: $colorD;
      }
    }
  }
}

.footer {
  margin-top: 10%;
  p {
    text-align: center;
    span {
      color: $colorB;
      margin: 0.5%;
    }
  }
  :nth-child(1) {
    span {
      cursor: pointer;
    }
  }
}
</style>